import get from '@/utils/get'
import { getAppInfo } from '@/libs/app';
import { useCounterStore } from '@/store/useCounterStore';

function loginbycode(to:any, from:any, next:any) {
    const authStore = useCounterStore();
    // 初始化登录状态
    authStore.initialize();
    next()
}

function updateTitle(to:any) {
    document.title = get(to, 'meta.title.zh') || getAppInfo().appName
}

export default function hook(router:any): void {
    router.beforeEach(loginbycode)
    router.afterEach(updateTitle);
}